The present invention is directed to an improvement in computing systems and in particular to computer systems which provide for the mapping of relational tables to object oriented classes.
Data is often stored in relational database systems. Such relational database systems model the data as tables and offer relational operators such as SELECT, INSERT, UPDATE and DELETE for data manipulation. Relational database systems are frequently used as xe2x80x9cbackendxe2x80x9d systems which are in turn accessed by another computer program or system application which accesses the data in the relational database tables. This access may be accomplished by the other application including code which directly uses the application program interface (API) of the relational database in which the data is stored. For the relational database to be accessed directly in this way the programmer writing the application must have knowledge of the underlying API for the relational database. Typically, such code in the application program is written specifically for a given structure of database and therefore when the database is changed in some way the code must also be changed. It is now quite common for object oriented applications to access relational database backend systems. For a programmer writing in an object oriented environment it is advantageous to be able to model the data as object oriented classes, rather than to require the programmer to have knowledge of the details of the relational database being accessed. With the increasing popularity of object oriented styles of programming, such a mapping of relational tables to classes is relatively common. One approach to this mapping is to store the relational database operators and definitions statically in defined classes in the object oriented system. Classes are defined on a table by table basis and operations for the classes are defined in relation to the structure of the tables mapped. Such a system has limited flexibility. In addition, the implementation of relational operators in the object oriented system will often result in inefficient relational operations being carried out. For example, an object oriented implementation of a relational UPDATE operator may result in a global update (all fields are updated) where a more selective update may be appropriate and potentially be more efficient.
An example of the prior art approach is found in U.S. Pat. No. 5,694,598 (Durand) which discloses a method for mapping data between object oriented object and a relational database. The method disclosed requires the generation of a transit object from objects in the object oriented environment and populating the transit object with data which is then used to populate a relational database. The mapping may also be carried out in reverse.
Another prior approach to the mapping between relational tables and object oriented constructs is provided in U.S. Pat. No. 5,499,371 (Henninger). The method disclosed in that patent requires the definition of an object model which represents the structure of a given relational database table. This object model is used in conjunction with a database schema and transform to create the mapping between the relational table and the object oriented environment.
Another approach is found in U.S. Pat. No. 5,596,746 (Shen) which discloses the use of meta models of database tables to permit relational tables to be mapped to an object model representation.
The prior art approaches require specific data constructs such as transit objects, object models and meta models for the mapping of the relational data to the object oriented environment. Such approaches potentially constrain the object oriented programmer in developing or modifying object oriented models for mapping relational tables.
It is therefore desirable to have a computer system which will permit the mapping of relational database tables to object oriented classes where the object oriented system retains flexibility to accommodate changes in the relational database and which has increased efficiency.
According to one aspect of the present invention, there is provided an improved system for mapping relational database tables to object oriented classes.
According to another aspect of the present invention, there is provided a computer system framework for mapping relational database tables to object oriented classes, the framework including an attribute class for mapping data values from a relational table column to values in an object oriented environment, the attribute class comprising data objects representing data types, a data object for data from the relational table, and methods to access the data objects in the attribute class, a generator class for providing methods to permit the generation of SQL statements for relational tables defined by attribute class objects, whereby a programmer may define a table class corresponding to a relational table, the table class using the attribute class and the generator class of the framework to define the columns of the table in the object oriented environment and to define specific operations on the relational table.
According to another aspect of the present invention, there is provided the above framework in which the data objects representing data types in the attribute class comprise a column name object, an SQL type object and an object oriented mapping type object.
According to another aspect of the present invention, there is provided the above framework in which the attribute class further includes data object flags comprising an index flag indicating whether the relational table column mapped by the attribute class object is part of a target index for a given SQL statement.
According to another aspect of the present invention, there is provided the above framework in which the attribute class further includes data object flags comprising a modified flag indicating whether the attribute value in the attribute class object has been modified.
According to another aspect of the present invention, there is provided the above framework in which the attribute class further includes data object flags comprising a bindable flag indicating whether the attribute value in the attribute class object is to be bound to a parameter marker for a given SQL statement, and an associated update string data object comprising an SQL fragment to be bound to the parameter marker where the attribute value is not to be so bound.
According to another aspect of the present invention, there is provided the above framework in which the generator class includes methods to generate text for SQL statements comprising SELECT, INSERT, UPDATE, and DELETE and further includes methods to bind values to the statements passed to the relational table database.
According to another aspect of the present invention, there is provided the above framework in which the methods to generate the SELECT statement further includes a method to extract values from a fetched row of a relational table for use in a corresponding attribute class object.
According to another aspect of the present invention, there is provided a computer program product for use with a computer comprising a central processing unit and random access memory, said computer program product comprising a computer usable medium having computer readable code means embodied in said medium providing a framework for the mapping of relational data tables to object oriented classes, said computer program product comprising computer readable program code means the above framework.
According to another aspect of the present invention, there is provided a computer program product tangibly embodying a program of instructions executable by a computer for providing the above framework for the mapping of relational data tables to object oriented classes.
According to another aspect of the present invention, there is provided a method for mapping relational database tables to object oriented classes, the method comprising the following steps:
defining an attribute class for mapping data values from a relational table column to values in an object oriented environment, the attribute class comprising data objects representing data types, a data object for data from the relational table, and methods to access the data objects in the attribute class,
defining a generator class for providing methods to permit the generation of SQL statements for relational tables defined by attribute class objects,
defining a table class corresponding to a relational table, the table class using the attribute class and the generator class of the framework to define the columns of the table in the object oriented environment and to define specific operations on the relational table.
Advantages of the present invention include the fact that use of the framework of the invention permits object oriented code to be written in a flexible and powerful way to permit accesses to relational database tables without the programmer relying on knowledge of details of the underlying database table.